package cn.itcast.web.servlet;

import cn.itcast.daomain.purchase;
import cn.itcast.service.UserService;
import cn.itcast.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/myOrderServlet")
public class MyOrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session=request.getSession();
        Object seess=request.getSession().getAttribute("usersList");
        Map<String, String> objMap = null;
        String id=null;
        try {
            objMap = BeanUtils.describe(seess);
            id = objMap.get("user_pur");

        } catch (Exception e) {
            e.printStackTrace();
        }

        UserService service=new UserServiceImpl();

        List<purchase> pur=service.selecPur(id);

        request.setAttribute("myorder",pur);
        request.getRequestDispatcher("/Word.jsp").forward(request,response);


    }
}
